<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        li {
            list-style: none;
        }

        .box {
            width: 800px;
            margin: 100px auto;
        }

        #hd {
            height: 50px;
            background-color: #f4f4f4;
            border-bottom: 3px solid black;
        }

        #hd li {
            float: left;
            width: 150px;
            height: 50px;
            margin: 0 25px;
            text-align: center;
            line-height: 50px;
        }

        .hove {
            background-color: black;
            color: #f4f4f4;
        }

        #bd {
            width: 800px;
            background-color: green;
        }

        #bd li {
            height: 200px;
            background-color: black;
            display: none;
            color: white;
            font-size: 30px;
        }
    </style>
</head>

<body>
    <div class="box">
        <ul id="hd">
            <li class="hove">商品介绍</li>
            <li>规格和包装</li>
            <li>售后保障</li>
            <li>商品评价</li>
        </ul>
        <ul id="bd">
            <li>商品介绍</li>
            <li>规格和包装</li>
            <li>售后保障</li>
            <li>商品评价</li>
        </ul>

    </div>

</body>
<script>
    var li = document.querySelector('#hd').querySelectorAll('li')
    var bd = document.querySelector('#bd').querySelectorAll('li')
    console.log(li);
    for (var i = 0; i < li.length; i++) {
        li[i].setAttribute('index', i);
        li[i].onclick = function () {
            for (var j = 0; j < li. length; j++) {
                li[j].className = '';
            }
            this.className = 'hove';
            var index=this.getAttribute('index')
            for (var i = 0; i < bd.length; i++) {
                bd[i].style.display = 'none';
            }
            bd[index].style.display = 'block';

        }

    }

</script>

</html>